
function checkDate(date)
{
  for(var i = 0; i < dates.length; i++) {
    if(date == dates[i])
       return true;
  }
  return false;
}

function checkTrain(train)
{
  for(var i = 0; i < trains.length; i++) {
    if(train == trains[i])
       return true;
  }
  return false;

}


function isRequestedTicket(href)
{
      // parse the href
      var result = XMLHTTPResponse(href);
      
      var data = result.jhe_im("TABLE", "@id=viewAttributes");
      
       var tabledatas = data[0].jhe_mt("td");
       var tabledata;
       for(var i = 0; i < tabledatas.length; i++){
          tabledata = tabledatas[i];
          if(i == 3) // train
          {    
             if(checkTrain(tabledata.substring(3)) == false)
             {
                return false;
             }
          }
          if(i == 5) //date
          {
             var year, month, day;
             year = tabledata.substr(5, 4);
             month = tabledata.substr(10, 2);
             day = tabledata.substr(13, 2);
             if(checkDate(year+month+day)== false)
             {
                return false;
             }
          }

       }   

      return true;
}



var rows, row;

// get all tr with class("row clik")
rows = document.evaluate(
    "//TR[@class='row clik']",
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null);

if(rows.snapshotLength) {
   var found = 0;
  for (var i = 0; i < rows.snapshotLength; i++) {
    row = rows.snapshotItem(i);
    // get the link for this item... 
    var href = row.firstChild.firstChild.href;
    // for debug
   
      if(isRequestedTicket(href))
      {
	   row.style.color = 'red';
          found = found+1;
       }
   
  }
 if (found>0)
   alert("found " + found + " items\nthey are all highlighted...");
}

setTimeout("window.location.href=window.location.href",   60000);   